home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2006 May / PCWMAY06.iso / Software / Toolkit / Songbird 0.1 / Songbird_0_1_0.exe / components / sbIDynamicPlaylist.js < prev    next >
Text File  |  2006-02-07  |  22KB  |  768 lines

  1. /*
  2.  //
  3. // BEGIN SONGBIRD GPL
  4. // 
  5. // This file is part of the Songbird web player.
  6. //
  7. // Copyright⌐ 2006 Pioneers of the Inevitable LLC
  8. // http://songbirdnest.com
  9. // 
  10. // This file may be licensed under the terms of of the
  11. // GNU General Public License Version 2 (the ôGPLö).
  12. // 
  13. // Software distributed under the License is distributed 
  14. // on an ôAS ISö basis, WITHOUT WARRANTY OF ANY KIND, either 
  15. // express or implied. See the GPL for the specific language 
  16. // governing rights and limitations.
  17. //
  18. // You should have received a copy of the GPL along with this 
  19. // program. If not, go to http://www.gnu.org/licenses/gpl.html
  20. // or write to the Free Software Foundation, Inc., 
  21. // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  22. // 
  23. // END SONGBIRD GPL
  24. //
  25.  */
  26.  
  27. //
  28. // sbIDynamicPlaylist Object
  29. //
  30.  
  31. const SONGBIRD_PLAYLIST_IID = Components.interfaces.sbIPlaylist;
  32.  
  33. const SONGBIRD_DYNAMICPLAYLIST_CONTRACTID = "@songbird.org/Songbird/DynamicPlaylist;1";
  34. const SONGBIRD_DYNAMICPLAYLIST_CLASSNAME = "Songbird Dynamic Playlist Interface"
  35. const SONGBIRD_DYNAMICPLAYLIST_CID = Components.ID('{8A1A3D68-E3A4-484b-B9A5-4088ADEDA5B3}');
  36. const SONGBIRD_DYNAMICPLAYLIST_IID = Components.interfaces.sbIDynamicPlaylist;
  37.  
  38. const DYNAMICPLAYLIST_LIST_TABLE_NAME = "dynamicplaylist_list";
  39.  
  40. function CDynamicPlaylist()
  41. {
  42.   var query = Components.classes["@songbird.org/Songbird/DatabaseQuery;1"].createInstance();
  43.   query = query.QueryInterface(Components.interfaces.sbIDatabaseQuery);
  44.  
  45.   this.m_internalQueryObject = query;
  46. }
  47.  
  48. CDynamicPlaylist.prototype.constructor = CDynamicPlaylist;
  49.  
  50. /* the CPlaylist class def */
  51. CDynamicPlaylist.prototype = 
  52. {
  53.   m_strName: "",
  54.   m_strReadableName: "",
  55.   m_queryObject: null,
  56.   m_internalQueryObject: null,
  57.   
  58.   SetQueryObject: function(queryObj)
  59.   {
  60.     this.m_queryObject = queryObj; 
  61.     this.m_internalQueryObject.SetDatabaseGUID(queryObj.GetDatabaseGUID());
  62.     return;
  63.   },
  64.   
  65.   GetQueryObject: function()
  66.   {
  67.     return this.m_queryObject;
  68.   },
  69.   
  70.   AddByGUID: function(mediaGUID, serviceGUID, nPosition, bReplace, bWillRunLater)
  71.   {
  72.     if(this.m_queryObject != null)
  73.     {
  74.       if(!bWillRunLater)
  75.         this.m_queryObject.ResetQuery();
  76.       
  77.       if(bReplace)
  78.       {
  79.         var index = this.FindByGUID(mediaGUID);
  80.         if(index != -1)
  81.           return true;
  82.       }
  83.  
  84.       this.m_queryObject.AddQuery("INSERT INTO \"" + this.m_strName + "\" (playlist_uuid, playlist_service_uuid) VALUES (\"" + mediaGUID + "\", \"" + serviceGUID + "\")");
  85.       
  86.       if(!bWillRunLater)
  87.       {
  88.         this.m_queryObject.Execute();
  89.         this.m_queryObject.WaitForCompletion();
  90.       }
  91.       
  92.       return true;
  93.     }
  94.     
  95.     return false;
  96.   },
  97.   
  98.   RemoveByGUID: function(mediaGUID, bWillRunLater)
  99.   {
  100.     if(this.m_queryObject != null)
  101.     {
  102.       if(!bWillRunLater)
  103.         this.m_queryObject.ResetQuery();
  104.  
  105.       this.m_queryObject.AddQuery("DELETE FROM \"" + this.m_strName + "\" WHERE playlist_uuid = \"" + mediaGUID + "\"");
  106.       
  107.       if(!bWillRunLater)
  108.       {
  109.         this.m_queryObject.Execute();
  110.         this.m_queryObject.WaitForCompletion();
  111.       }
  112.       
  113.       return true;
  114.     }
  115.     
  116.     return false;
  117.   },
  118.   
  119.   RemoveByIndex: function(mediaIndex, bWillRunLater)
  120.   {
  121.     if(this.m_queryObject != null)
  122.     {
  123.       if(!bWillRunLater)
  124.         this.m_queryObject.ResetQuery();
  125.  
  126.       this.m_queryObject.AddQuery("DELETE FROM \"" + this.m_strName + "\" WHERE playlist_id = \"" + mediaIndex + "\"");
  127.       
  128.       if(!bWillRunLater)
  129.       {
  130.         this.m_queryObject.Execute();
  131.         this.m_queryObject.WaitForCompletion();
  132.       }
  133.       
  134.       return true;
  135.     }
  136.     
  137.     return false;
  138.   },
  139.   
  140.   MoveByGUID: function(mediaGUID, nPosition)
  141.   {
  142.     if(m_queryObject != null)
  143.     {
  144.       
  145.       return true;
  146.     }
  147.  
  148.     return false;
  149.   },
  150.   
  151.   MoveByIndex: function(mediaIndex, nPosition)
  152.   {
  153.     if(m_queryObject != null)
  154.     {
  155.       
  156.       return true;
  157.     }
  158.  
  159.     return false;
  160.   },
  161.  
  162.   FindByGUID: function(mediaGUID)
  163.   {
  164.     if(this.m_internalQueryObject != null)
  165.     {
  166.       this.m_internalQueryObject.ResetQuery();
  167.       this.m_internalQueryObject.AddQuery("SELECT playlist_id FROM \"" + this.m_strName + "\" WHERE playlist_uuid = \"" + mediaGUID + "\"");
  168.       
  169.       this.m_internalQueryObject.Execute();
  170.       this.m_internalQueryObject.WaitForCompletion();
  171.       
  172.       var resObj = this.m_internalQueryObject.GetResultObject();
  173.       
  174.       if(resObj.GetRowCount())
  175.         return resObj.GetRowCell(0, 0);
  176.     }
  177.     
  178.     return -1;
  179.   },
  180.   
  181.   FindByIndex: function(mediaIndex)
  182.   {
  183.     if(this.m_internalQueryObject != null)
  184.     {
  185.       this.m_internalQueryObject.ResetQuery();
  186.       this.m_internalQueryObject.AddQuery("SELECT playlist_uuid FROM \"" + this.m_strName + "\" WHERE playlist_id = \"" + nIndex + "\"");
  187.       
  188.       this.m_internalQueryObject.Execute();
  189.       this.m_internalQueryObject.WaitForCompletion();
  190.       
  191.       var resObj = this.m_internalQueryObject.GetResultObject();
  192.       if(resObj.GetRowCount())
  193.         return resObj.GetRowCell(0, 0);
  194.     }
  195.     
  196.     return "";
  197.   },
  198.  
  199.   GetColumnInfo: function()
  200.   {
  201.     if(this.m_queryObject != null)
  202.     {
  203.       this.m_queryObject.ResetQuery();
  204.       this.m_queryObject.AddQuery("SELECT * FROM \"" + this.m_strName + "_desc\" UNION SELECT * FROM library_desc ORDER BY sort_weight, column_name ASC");
  205.       
  206.       this.m_queryObject.Execute();
  207.       this.m_queryObject.WaitForCompletion();
  208.     }
  209.   },
  210.   
  211.   SetColumnInfo: function(strColumn, strReadableName, isVisible, defaultVisibility, isMetadata, sortWeight, colWidth, bWillRunLater)
  212.   {
  213.     if(this.m_queryObject != null)
  214.     {
  215.       if(!bWillRunLater)
  216.         this.m_queryObject.ResetQuery();
  217.       
  218.       var strQuery = "UPDATE \"" + this.m_strName + "_desc\" SET ";
  219.       strQuery += "readable_name = \"" + strReadableName + "\", ";
  220.       strQuery += "is_visible = \"" + isVisible ? 1: 0 + "\", ";
  221.       strQuery += "default_visibility = \"" + defaultVisibility ? 1 : 0 + "\", ";
  222.       strQuery += "is_metadata = \"" + isMetadata ? 1 : 0 + "\", ";
  223.       strQuery += "sort_weight = \"" + sortWeight + "\", ";
  224.       strQuery += "width = \"" + colWidth + "\" ";
  225.       strQuery += "WHERE column_name = \"" + strColumn + "\"";
  226.       
  227.       this.m_queryObject.AddQuery(strQuery);
  228.       
  229.       strQuery = "UPDATE \"library_desc\" SET ";
  230.       strQuery += "readable_name = \"" + strReadableName + "\", ";
  231.       strQuery += "is_visible = \"" + isVisible ? 1: 0 + "\", ";
  232.       strQuery += "default_visibility = \"" + defaultVisibility ? 1 : 0 + "\", ";
  233.       strQuery += "is_metadata = \"" + isMetadata ? 1 : 0 + "\", ";
  234.       strQuery += "sort_weight = \"" + sortWeight + "\", ";
  235.       strQuery += "width = \"" + colWidth + "\" ";
  236.       strQuery += "WHERE column_name = \"" + strColumn + "\"";
  237.       
  238.       this.m_queryObject.AddQuery(strQuery);
  239.       
  240.       if(!bWillRunLater)
  241.       {
  242.         this.m_queryObject.Execute();
  243.         this.m_queryObject.WaitForCompletion();
  244.       }
  245.     }    
  246.   },
  247.  
  248.   GetTableInfo: function()
  249.   {
  250.     if(this.m_queryObject != null)
  251.     {
  252.       this.m_queryObject.ResetQuery();
  253.       this.m_queryObject.AddQuery("PRAGMA table_info(\"" + this.m_strName + "\")");
  254.       
  255.       this.m_queryObject.Execute();
  256.       this.m_queryObject.WaitForCompletion();
  257.     }
  258.   },
  259.   
  260.   AddColumn: function(strColumn, strDataType)
  261.   {
  262.     if(this.m_queryObject != null)
  263.     {
  264.       this.m_queryObject.ResetQuery();
  265.       this.m_queryObject.AddQuery("ALTER TABLE \"" + this.m_strName + "\" ADD COLUMN \"" + strColumn + "\" " + strDataType);
  266.       this.m_queryObject.AddQuery("INSERT OR REPLACE INTO \"" + this.m_strName + "_desc\" (column_name) VALUES (\"" + strColumn + "\")");
  267.       
  268.       this.m_queryObject.Execute();
  269.       this.m_queryObject.WaitForCompletion();
  270.     }
  271.  
  272.     return;
  273.   },
  274.   
  275.   DeleteColumn: function(strColumn)
  276.   {
  277.     return;
  278.   },
  279.  
  280.   GetNumEntries: function()
  281.   {
  282.     if(this.m_queryObject != null)
  283.     {
  284.       this.m_queryObject.ResetQuery();
  285.       this.m_queryObject.AddQuery("SELECT COUNT(playlist_id) FROM \"" + this.m_strName + "\"");
  286.       
  287.       this.m_queryObject.Execute();
  288.       this.m_queryObject.WaitForCompletion();
  289.       
  290.       var resObj = this.m_queryObject.GetResultObject();
  291.       
  292.       return resObj.GetRowCell(0, 0);
  293.     }
  294.     
  295.     return 0;
  296.   },  
  297.   
  298.   GetEntry: function(nEntry)
  299.   {
  300.     if(this.m_queryObject != null)
  301.     {
  302.       this.m_queryObject.ResetQuery();
  303.       this.m_queryObject.AddQuery("SELECT * FROM \"" + this.m_strName + "\" WHERE playlist_id = \"" + nEntry + "\"");
  304.       
  305.       this.m_queryObject.Execute();
  306.       this.m_queryObject.WaitForCompletion();
  307.  
  308.       return 1;
  309.     }
  310.     
  311.     return 0;
  312.   },
  313.  
  314.   GetAllEntries: function()
  315.   {
  316.     if(this.m_queryObject != null)
  317.     {
  318.       this.m_queryObject.ResetQuery();
  319.       this.m_queryObject.AddQuery("SELECT * FROM \"" + this.m_strName + "\"");
  320.       
  321.       this.m_queryObject.Execute();
  322.       this.m_queryObject.WaitForCompletion();
  323.       
  324.       var resObj = this.m_queryObject.GetResultObject();
  325.       return resObj.GetRowCount();
  326.     }
  327.     
  328.     return 0;
  329.   },
  330.  
  331.   GetColumnValueByIndex: function(mediaIndex, strColumn)
  332.   {
  333.     if(this.m_queryObject != null)
  334.     {
  335.       this.m_queryObject.ResetQuery();
  336.       this.m_queryObject.AddQuery("SELECT " + strColumn + " FROM \"" + this.m_strName + "\" WHERE playlist_id = \"" + mediaIndex + "\"");
  337.       
  338.       this.m_queryObject.Execute();
  339.       this.m_queryObject.WaitForCompletion();
  340.       
  341.       var resObj = this.m_queryObject.GetResultObject();
  342.  
  343.       if(resObj.GetRowCount())
  344.         return resObj.GetRowCell(0, 0);
  345.     }
  346.         
  347.     return "";
  348.   },
  349.   
  350.   GetColumnValueByGUID: function(mediaGUID, strColumn)
  351.   {
  352.     if(this.m_queryObject != null)
  353.     {
  354.       this.m_queryObject.ResetQuery();
  355.       this.m_queryObject.AddQuery("SELECT " + strColumn + " FROM \"" + this.m_strName + "\" WHERE playlist_uuid = \"" + mediaGUID + "\"");
  356.       
  357.       this.m_queryObject.Execute();
  358.       this.m_queryObject.WaitForCompletion();
  359.       
  360.       var resObj = this.m_queryObject.GetResultObject();
  361.  
  362.       if(resObj.GetRowCount())
  363.         return resObj.GetRowCell(0, 0);    
  364.     }
  365.       
  366.     return "";
  367.   },
  368.  
  369.   GetColumnValuesByIndex: function(mediaIndex, nColumnCount, aColumns, nValueCount)
  370.   {
  371.     nValueCount = 0;
  372.     var aValues = new Array();
  373.  
  374.     if(this.m_queryObject != null)
  375.     {
  376.       var strQuery = "SELECT ";
  377.       this.m_queryObject.ResetQuery();
  378.       
  379.       var i = 0;
  380.       for( ; i < nColumnCount; i++)
  381.       {
  382.         strQuery += aColumns[i];
  383.         
  384.         if(i < nColumnCount - 1)
  385.           strQuery += ", ";
  386.       }
  387.       
  388.       strQuery += " FROM \"" + this.m_strName + "\" WHERE playlist_id = \"" + mediaIndex + "\"";
  389.       this.m_queryObject.AddQuery(strQuery);
  390.       
  391.       this.m_queryObject.Execute();
  392.       this.m_queryObject.WaitForCompletion();
  393.       
  394.       var resObj = this.m_queryObject.GetResultObject();
  395.       nValueCount = resObj.GetColumnCount();
  396.       
  397.       for(var i = 0; i < nValueCount; i++)
  398.       {
  399.         aValues.push(resObj.GetRowCell(0, i));
  400.       }    
  401.     }
  402.     
  403.     return aValues;
  404.   },
  405.   
  406.   GetColumnValuesByGUID: function(mediaGUID, nColumnCount, aColumns, nValueCount)
  407.   {
  408.     nValueCount = 0;
  409.     var aValues = new Array();
  410.  
  411.     if(this.m_queryObject != null)
  412.     {
  413.       var strQuery = "SELECT ";
  414.       this.m_queryObject.ResetQuery();
  415.       
  416.       var i = 0;
  417.       for( ; i < nColumnCount; i++)
  418.       {
  419.         strQuery += aColumns[i];
  420.         
  421.         if(i < nColumnCount - 1)
  422.           strQuery += ", ";
  423.       }
  424.       
  425.       strQuery += " FROM \"" + this.m_strName + "\" WHERE playlist_uuid = \"" + mediaGUID + "\"";
  426.       this.m_queryObject.AddQuery(strQuery);
  427.       
  428.       this.m_queryObject.Execute();
  429.       this.m_queryObject.WaitForCompletion();
  430.       
  431.       var resObj = this.m_queryObject.GetResultObject();
  432.       nValueCount = resObj.GetColumnCount();
  433.       
  434.       for(var i = 0; i < nValueCount; i++)
  435.       {
  436.         aValues.push(resObj.GetRowCell(0, i));
  437.       }    
  438.     }
  439.     
  440.     return aValues;
  441.   },
  442.   
  443.   SetColumnValueByIndex: function(mediaIndex, strColumn, strValue)
  444.   {
  445.     if(this.m_queryObject != null)
  446.     {
  447.       if(!bWillRunLater)
  448.         this.m_queryObject.ResetQuery();
  449.       
  450.       strValue = strValue.replace(/"/g, "\"\"");
  451.       this.m_queryObject.AddQuery("UPDATE \"" + this.m_strName + "\" SET " + strColumn + " = \"" + strValue + "\" WHERE playlist_id = \"" + mediaIndex + "\"");
  452.       
  453.       if(!bWillRunLater)
  454.       {
  455.         this.m_queryObject.Execute();
  456.         this.m_queryObject.WaitForCompletion();
  457.       }
  458.     }
  459.     
  460.     return;
  461.   },
  462.   
  463.   SetColumnValueByGUID: function(mediaGUID, strColumn, strValue)
  464.   {
  465.     if(this.m_queryObject != null)
  466.     {
  467.       if(!bWillRunLater)
  468.         this.m_queryObject.ResetQuery();
  469.       
  470.       strValue = strValue.replace(/"/g, "\"\"");
  471.       this.m_queryObject.AddQuery("UPDATE \"" + this.m_strName + "\" SET " + strColumn + " = \"" + strValue + "\" WHERE playlist_uuid = \"" + mediaGUID + "\"");
  472.       
  473.       if(!bWillRunLater)
  474.       {
  475.         this.m_queryObject.Execute();
  476.         this.m_queryObject.WaitForCompletion();
  477.       }
  478.     }
  479.     
  480.     return;
  481.   },
  482.  
  483.   SetColumnValuesByIndex: function(mediaIndex, nColumnCount, aColumns, nValueCount, aValues)
  484.   {
  485.     if(this.m_queryObject != null ||
  486.        nColumnCount != nValueCount)
  487.     {
  488.       if(!bWillRunLater)
  489.         this.m_queryObject.ResetQuery();
  490.       
  491.       var strQuery = "UPDATE \"" + this.m_strName + "\" SET ";
  492.       var i = 0;
  493.       for(; i < nColumnCount; i++)
  494.       {
  495.         aValues[i] = aValues[i].replace(/"/g, "\"\"");
  496.         strQuery += aColumns[i] + " = \"" + aValues[i] + "\"";
  497.         if(i < nColumnCount - 1)
  498.           strQuery += ", ";
  499.       }
  500.       
  501.       strQuery += " WHERE id = \"" + mediaIndex + "\"";
  502.       this.m_queryObject.AddQuery(strQuery);
  503.       
  504.       if(!bWillRunLater)
  505.       {
  506.         this.m_queryObject.Execute();
  507.         this.m_queryObject.WaitForCompletion();
  508.       }
  509.     }
  510.  
  511.     return;
  512.   },
  513.   
  514.   SetColumnValuesByGUID: function(mediaGUID, nColumnCount, aColumns, nValueCount, aValues)
  515.   {
  516.     if(this.m_queryObject != null ||
  517.        nColumnCount != nValueCount)
  518.     {
  519.       if(!bWillRunLater)
  520.         this.m_queryObject.ResetQuery();
  521.       
  522.       var strQuery = "UPDATE \"" + this.m_strName + "\" SET ";
  523.       var i = 0;
  524.       for(; i < nColumnCount; i++)
  525.       {
  526.         aValues[i] = aValues[i].replace(/"/g, "\"\"");
  527.         strQuery += aColumns[i] + " = \"" + aValues[i] + "\"";
  528.         if(i < nColumnCount - 1)
  529.           strQuery += ", ";
  530.       }
  531.       
  532.       strQuery += " WHERE playlist_uuid = \"" + mediaGUID + "\"";
  533.       this.m_queryObject.AddQuery(strQuery);
  534.       
  535.       if(!bWillRunLater)
  536.       {
  537.         this.m_queryObject.Execute();
  538.         this.m_queryObject.WaitForCompletion();
  539.       }
  540.     }
  541.  
  542.     return;
  543.   },
  544.   
  545.   SetName: function(strName)
  546.   {
  547.     this.m_strName = strName;
  548.     return;
  549.   },
  550.   
  551.   GetName: function()
  552.   {
  553.     return this.m_strName;
  554.   },
  555.   
  556.   SetReadableName: function(strReadableName)
  557.   {
  558.     this.m_queryObject.ResetQuery();
  559.     
  560.     strReadableName = strReadableName.replace(/"/g, "\"\"");
  561.     this.m_queryObject.AddQuery("UPDATE " + DYNAMICPLAYLIST_LIST_TABLE_NAME + " SET readable_name = \"" + strReadableName + "\" WHERE name = \"" + this.m_strName + "\"");
  562.     
  563.     this.m_queryObject.Execute();
  564.     this.m_queryObject.WaitForCompletion();
  565.     
  566.     return;
  567.   },
  568.   
  569.   GetReadableName: function()
  570.   {
  571.     var strReadableName = "";
  572.     this.m_queryObject.ResetQuery();
  573.     this.m_queryObject.AddQuery("SELECT readable_name FROM " + DYNAMICPLAYLIST_LIST_TABLE_NAME + " WHERE name = \"" + this.m_strName + "\"");
  574.     
  575.     this.m_queryObject.Execute();
  576.     this.m_queryObject.WaitForCompletion();
  577.     
  578.     var resObj = this.m_queryObject.GetResultObject();
  579.     
  580.     if(resObj.GetRowCount())
  581.       strReadableName = resObj.GetRowCell(0, 0);    
  582.     
  583.     return strReadableName;
  584.   },
  585.  
  586.   SetPeriodicity: function(nPeriodicity, bWillRunLater)
  587.   {
  588.     if(this.m_queryObject != null)
  589.     {
  590.       if(!bWillRunLater)
  591.         this.m_queryObject.ResetQuery();
  592.       
  593.       this.m_queryObject.AddQuery("UPDATE \"" + DYNAMICPLAYLIST_LIST_TABLE_NAME + "\" SET periodicity  = \"" + nPeriodicity + "\" WHERE name = \"" + this.m_strName + "\"");
  594.       
  595.       if(!bWillRunLater)
  596.       {
  597.         this.m_queryObject.Execute();
  598.         this.m_queryObject.WaitForCompletion();
  599.       }
  600.     }
  601.     
  602.     return;
  603.   },
  604.   
  605.   GetPeriodicity: function()
  606.   {
  607.     if(this.m_queryObject != null)
  608.     {
  609.       this.m_queryObject.ResetQuery();
  610.       this.m_queryObject.AddQuery("SELECT periodicity FROM \"" + DYNAMICPLAYLIST_LIST_TABLE_NAME + "\" WHERE name = \"" + this.m_strName + "\"");
  611.       
  612.       this.m_queryObject.Execute();
  613.       this.m_queryObject.WaitForCompletion();
  614.       
  615.       var resObj = this.m_queryObject.GetResultObject();
  616.       if(resObj.GetRowCount > 0)
  617.       {
  618.         return resObj.GetRowCell(0, 0);
  619.       }
  620.     }
  621.     
  622.     return 0;
  623.   },
  624.   
  625.   SetURL: function(strURL, bWillRunLater)
  626.   {
  627.   if(this.m_queryObject != null)
  628.     {
  629.       if(!bWillRunLater)
  630.         this.m_queryObject.ResetQuery();
  631.       
  632.       this.m_queryObject.AddQuery("UPDATE " + DYNAMICPLAYLIST_LIST_TABLE_NAME + " SET url = \"" + strURL + "\" WHERE name = \"" + this.m_strName + "\"");
  633.       
  634.       if(!bWillRunLater)
  635.       {
  636.         this.m_queryObject.Execute();
  637.         this.m_queryObject.WaitForCompletion();
  638.       }
  639.     }
  640.     
  641.     return;
  642.   },
  643.   
  644.   GetURL: function()
  645.   {
  646.     if(this.m_queryObject != null)
  647.     {
  648.       this.m_queryObject.ResetQuery();
  649.       this.m_queryObject.AddQuery("SELECT url FROM \"" + DYNAMICPLAYLIST_LIST_TABLE_NAME + "\" WHERE name = \"" + this.m_strName + "\"");
  650.       
  651.       this.m_queryObject.Execute();
  652.       this.m_queryObject.WaitForCompletion();
  653.       
  654.       var resObj = this.m_queryObject.GetResultObject();
  655.       if(resObj.GetRowCount > 0)
  656.       {
  657.         return resObj.GetRowCell(0, 0);
  658.       }
  659.     }
  660.  
  661.     return "";
  662.   },
  663.  
  664.   SetLastUpdateTime: function()
  665.   {
  666.     if(this.m_queryObject != null)
  667.     {
  668.       var dNow = new Date();
  669.       
  670.       this.m_queryObject.ResetQuery();
  671.       this.m_queryObject.AddQuery("UPDATE \"" + DYNAMICPLAYLIST_LIST_TABLE_NAME + "\" SET last_update = " + dNow.getTime() + " WHERE name = \"" + this.m_strName + "\"");
  672.       
  673.       this.m_queryObject.Execute();
  674.       this.m_queryObject.WaitForCompletion();
  675.     }    
  676.   },
  677.   
  678.   GetLastUpdateTime: function()
  679.   {
  680.     if(this.m_queryObject != null)
  681.     {
  682.       this.m_queryObject.ResetQuery();
  683.       this.m_queryObject.AddQuery("SELECT last_update FROM \"" + DYNAMICPLAYLIST_LIST_TABLE_NAME + "\" WHERE name = \"" + this.m_strName + "\"");
  684.       
  685.       this.m_queryObject.Execute();
  686.       this.m_queryObject.WaitForCompletion();
  687.       
  688.       var resObj = this.m_queryObject.GetResultObject();
  689.       if(resObj.GetRowCount > 0)
  690.       {
  691.         return resObj.GetRowCell(0, 0);
  692.       }
  693.     }
  694.  
  695.     return 0;
  696.   },
  697.  
  698.   QueryInterface: function(iid)
  699.   {
  700.       if (!iid.equals(Components.interfaces.nsISupports) &&
  701.           !iid.equals(SONGBIRD_DYNAMICPLAYLIST_IID) && 
  702.           !iid.equals(SONGBIRD_PLAYLIST_IID))
  703.           throw Components.results.NS_ERROR_NO_INTERFACE;
  704.       return this;
  705.   }
  706. };
  707.  
  708. /**
  709.  * \class sbDynamicPlaylistModule
  710.  * \brief 
  711.  */
  712. var sbDynamicPlaylistModule = 
  713. {
  714.   registerSelf: function(compMgr, fileSpec, location, type)
  715.   {
  716.       compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
  717.       compMgr.registerFactoryLocation(SONGBIRD_DYNAMICPLAYLIST_CID, 
  718.                                       SONGBIRD_DYNAMICPLAYLIST_CLASSNAME, 
  719.                                       SONGBIRD_DYNAMICPLAYLIST_CONTRACTID, 
  720.                                       fileSpec, 
  721.                                       location,
  722.                                       type);
  723.   },
  724.  
  725.   getClassObject: function(compMgr, cid, iid) 
  726.   {
  727.       if (!cid.equals(SONGBIRD_DYNAMICPLAYLIST_CID))
  728.           throw Components.results.NS_ERROR_NO_INTERFACE;
  729.  
  730.       if (!iid.equals(Components.interfaces.nsIFactory))
  731.           throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
  732.  
  733.       return sbDynamicPlaylistFactory;
  734.   },
  735.  
  736.   canUnload: function(compMgr)
  737.   { 
  738.     return true; 
  739.   }
  740. };
  741.  
  742. /**
  743.  * \class sbDynamicPlaylistFactory
  744.  * \brief 
  745.  */
  746. var sbDynamicPlaylistFactory =
  747. {
  748.     createInstance: function(outer, iid)
  749.     {
  750.         if (outer != null)
  751.             throw Components.results.NS_ERROR_NO_AGGREGATION;
  752.     
  753.         if (!iid.equals(SONGBIRD_DYNAMICPLAYLIST_IID) &&
  754.             !iid.equals(Components.interfaces.nsISupports))
  755.             throw Components.results.NS_ERROR_INVALID_ARG;
  756.  
  757.         return (new CDynamicPlaylist()).QueryInterface(iid);
  758.     }
  759. }; //sbDynamicPlaylistFactory
  760.  
  761. /**
  762.  * \function NSGetModule
  763.  * \brief 
  764.  */
  765. function NSGetModule(comMgr, fileSpec)
  766.   return sbDynamicPlaylistModule;
  767. } //NSGetModule